package pers.corvey.crawler.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class MovieCelebrity {

	private String movieId;
	private String celebrityId;
	private String type;
	
	public MovieCelebrity() {}

	public static List<MovieCelebrity> create4Work(Celebrity celebrity) {
		String celebrityId = celebrity.getId(); 
		if (celebrityId == null) {
			throw new IllegalArgumentException("celebrity的ID不能为空！");
		}
		List<MovieCelebrity> ret = new ArrayList<>();
		for (Movie movie : celebrity.getWorks()) {
			MovieCelebrity mc = new MovieCelebrity();
			mc.setMovieId(movie.getId());
			mc.setCelebrityId(celebrityId);
			mc.setType("work");
			ret.add(mc);
		}
		return ret;
	}
	
	public static List<MovieCelebrity> create4Cast(Movie movie) {
		return createMovieCelebrity(movie.getId(), movie.getCasts(), "cast");
	}
	
	public static List<MovieCelebrity> create4Director(Movie movie) {
		return createMovieCelebrity(movie.getId(), movie.getDirectors(), "director");
	}
	
	private static List<MovieCelebrity> createMovieCelebrity(
			String movieId, List<Celebrity> celebrities, String type) {
		if (movieId == null) {
			throw new IllegalArgumentException("movie的ID不能为空！");
		}
		List<MovieCelebrity> ret = new ArrayList<>();
		for (Celebrity celebrity : celebrities) {
			MovieCelebrity mc = new MovieCelebrity();
			mc.setMovieId(movieId);
			mc.setCelebrityId(celebrity.getId());
			mc.setType(type);
			ret.add(mc);
		}
		return ret;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
	}
	
	public String getMovieId() {
		return movieId;
	}

	public void setMovieId(String movieId) {
		this.movieId = movieId;
	}

	public String getCelebrityId() {
		return celebrityId;
	}

	public void setCelebrityId(String celebrityId) {
		this.celebrityId = celebrityId;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
}
